SELect ON

Syntax: SELect ON var
Location: QL ROM

This command is used to mark the start of a SuperBASIC structure which is an extremely quick means of testing for various values of a variable and taking a different course of action in a program according to those values. Unfortunately, the standard form of this command only allows you to test for different values of a numeric variable (eg. SELect ON a$ is not allowed).

There are actually two forms of the SuperBASIC structure:

SELect ON var=range: statement {:statement}{:=range:statement {:statement}}
or
SELect ON var
{[ON var] = range:statement {:statement} }
..
END SELect

range can be any one, or mixtures of, the following:   
expression   
expression TO expression   
REMAINDER

The in-line variant does not need END SELect to mark the end of the structure.

After the main SELect ON var statement, the interpreter looks for a list of possible values, and then if the value of the given variable falls within the range of possible values, the program takes action according to the statements which follow that value in the list. The interpreter will use the first range of values into which it can fit the variable and once found, all statements up until (but excluding) the next range in the list will be treated as applying to that range (whether they appear on the same line or not). 

Once all of the statements applying to that range have been executed, control passes to the statement following the END SELect statement (or if the in-line form of the structure is used, and END SELect does not appear on that line, then control passes to the next line).

The way in which matches are made when checking whether a value falls within a range depends on whether range is a single number (eg. ON var=10) or various values (eg. ON var=10 to 20).

If the former, the value need only be approximately equal to range (ie. to within 1 part in 107, for instance: 100.0000045==100!). However, if the latter format is used (eg. SELect ON a=90 TO 100), a match will only be found if the given value is within the absolute range (eg. in the above example, 100.0000045 would not be matched!).

If the long form of the structure is used, and ON var is used within the body of the structure, this must be the same variable as that used in the initial SELect ON statement.

Example:
10 SELect ON x=1,10 TO 100,500:PRINT 'x'

100 SELect ON test 
110   =0,2,4,6,8,10:PRINT 'Even Number'
120   =REMAINDER:PRINT 'Odd Number'
130 END SELect

MINERVA NOTES:
Minerva supports string and variables in SELect ON statements. The check for characters is normally case independent. For example:

SELect ON a$:='hello' 
will find both a$='HeLLo' and a$='hello'. If however, you want the match to be exact (case dependent), then something along the lines of:
SELect ON a$:='hello' TO 'hello'   
must be used.

Minerva also supports integer variables, such as: SELect ON a%. This is an extremely fast means of testing a condition. However, due to the nature of integers, tests will only match the integer part of range.

SMS NOTE:
This has greatly extended the flexibility of SELect ON.

It will also allow integer variables as the SELect, but unfortunately not string SELect variables at present.

It will however, even support things like:
SELect ON CODE(INKEY$(#1))

CROSS-REFERENCE:
A slower means of testing for values is the structure IF...END IF. 
END SELect ends a SELect ON structure.
